package cn.zyq.demo.service.file.impl;



import cn.zyq.demo.beans.file.FileStorage;
import cn.zyq.demo.beans.sys.SysAdmin;
import cn.zyq.demo.mapper.file.FileStorageMapper;
import cn.zyq.demo.service.file.FileStorageService;
import cn.zyq.demo.system.common.BaseService;
import cn.zyq.demo.system.common.PageParam;
import cn.zyq.demo.system.enums.core.DeletedTypeEnum;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 文件存储表
 * 2023-05-09 20:58:31
 */

@Slf4j
@Service
public class FileStorageServiceImpl extends BaseService implements FileStorageService {
    @Autowired
    private FileStorageMapper fileStorageMapper;


    @Override
    public PageInfo<FileStorage> list(PageParam pageParam, SysAdmin admin) {
        PageHelper.startPage(pageParam.getPage(), pageParam.getPageSize());
        List<FileStorage> dbList = this.fileStorageMapper.list(pageParam.getKv());
        return new PageInfo<>(dbList);
    }

    @Override
    public void add(FileStorage param, SysAdmin admin) {
        this.setCreateBaseData(param, admin);
        this.fileStorageMapper.insertSelective(param);
    }

    @Override
    public void update(FileStorage param, SysAdmin admin) {
        Integer id = param.getFileStorageID();
        this.setUpdateBaseData(param, admin);
        this.fileStorageMapper.updateByPrimaryKeySelective(param);
    }

    @Override
    public void del(String serviceID, SysAdmin admin) {
        FileStorage dbInfo = this.detail(serviceID);
        Integer id = dbInfo.getFileStorageID();
        this.deleteLogic(id, admin, this.fileStorageMapper);
    }

    @Override
    public FileStorage detail(String serviceID, SysAdmin admin) {
        return this.detail(serviceID);
    }

    @Override
    public FileStorage detail(String serviceID) {
        FileStorage dbInfo = this.getByServiceID(serviceID, FileStorage.class, this.fileStorageMapper);
        this.checkLogicExist(dbInfo);
        return dbInfo;
    }

    @Override
    public FileStorage findByKey(String key) {
        FileStorage storage = new FileStorage();
        storage.setKey(key);
        storage.setDeleted(DeletedTypeEnum.NORMAL.getValue());
        return fileStorageMapper.selectOne(storage);
    }
}
